package com.zy.core.service.impl;

import java.io.Serializable;
import java.util.List;

import com.zy.core.mapper.BaseMapper;
import com.zy.core.model.QueryResult;
import com.zy.core.service.BaseService;
import com.zy.core.web.form.BaseSearchForm;

/**
 * <p>服务支持<p>
 * 为服务组件的基类，必须继承
 * 
 * @author gaoyufeng
 * 
 * @param <T> 该服务组件服务的数据模型，即model;
 */
public abstract class ServiceSupport<T> implements BaseService<T> {
	
	
	private BaseMapper<T> mapper;
	
	public BaseMapper<T> getMapper() throws Exception{
		return mapper;
	}

	@Override
	public void save(T entity) throws Exception {
		getMapper().insert(entity);
	}

	@Override
	public void update(T entity) throws Exception{
		getMapper().update(entity);
	}

	@Override
	public void delete(Serializable id) throws Exception {
		getMapper().delete(id);
	}

	@Override
	public void batchDelete(Serializable[] ids) throws Exception {
		getMapper().batchDelete(ids);		
	}

	@Override
	public T find(Serializable id) throws Exception {
		return getMapper().selectById(id);
	}

	@Override
	public QueryResult<T> getData(BaseSearchForm form) throws Exception {
		QueryResult<T> qr = new QueryResult<T>();
		qr.setResultlist(getMapper().pageData(form));
		qr.setTotalrecord(getMapper().pageTotalRecord(form));
		return qr;
	}

	@Override
	public void updateBySelective(T entity) throws Exception {
		getMapper().updateBySelective(entity);		
	}

	@Override
	public Long count(BaseSearchForm form) throws Exception {
		return getMapper().count(form);
	}

	@Override
	public List<T> findAll(BaseSearchForm form) throws Exception {
		return getMapper().findAll(form);
	}
	
	
}
